import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

class Student{
	String stuno1;
	String name1;
	int age1;
	String birthdate1;
}
public class Main {
	 public static void displayAll(){
			String URL = "jdbc:mysql://localhost:3306/test";
			String driverName = "com.mysql.jdbc.Driver";
			//String userName = "root";//root
			//String password = "123456";//123456
			String sql = "select stuno,name,birthdate from student";
			Connection conn = null;
			
			try {
				Class.forName(driverName);
				conn = DriverManager.getConnection(URL);
				Statement statement = conn.createStatement();
				ResultSet resultSet = statement.executeQuery(sql);
				// id | stuno     | name | gender | birthdate  | major
				while(resultSet.next()){
					//int id = resultSet.getInt("id");
					String stuno = resultSet.getString("stuno");
					String name =resultSet.getString("name");
					Date date = resultSet.getDate("birthdate");
					System.out.print("stuno="+stuno+" name="+name+"    birthdate="+date);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(conn!=null)
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}//����ʹ��Try..with..resources�﷨��
				conn = null;
			}
	 } 
	 public static int insert(Student stu){
			String URL = "jdbc:mysql://localhost:3306/test";
			String driverName = "com.mysql.jdbc.Driver";
			//String userName = "root";//root
			//String password = "123456";//123456
			String sql = "insert into student(stuno,name,age,birthdate)values('2016039','andy',25,'1992-01-01')";
			//String sql = "insert into student(stuno,name,age,birthdate)values('2017039','yyyccc',22,'1995-01-01')";
			//String sql = "insert into student(stuno,name,age,birthdate)values('2018039','wwwxxx',21,'1993-01-01')";
			//String sql = "insert into student(stuno,name,age,birthdate)values('2019039','xxxccc',18,'1999-01-01')";
			Connection conn = null;
			try {
				Class.forName(driverName);
				conn = DriverManager.getConnection(URL);
				Statement statement = conn.createStatement();
				int resultSet = statement.executeUpdate(sql);			
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}finally{
				if(conn!=null)
					try {
						conn.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				conn = null;
			}
			return 0;
	 }

	public static void main(String[] args) {
		//displayAll();
		Student stu1 = null;
		insert(stu1);
	}

}
